#!/usr/bin/python
import os, time, sys, thread

from socket import *
myHost = ""
myPort = 51769

sockobj = socket(AF_INET, SOCK_STREAM)
sockobj.bind((myHost,myPort))
sockobj.listen(5) # 5 pending connects

def now():
    return time.ctime(time.time())

def handleClient(conn):
    time.sleep(5) ## blocking
    while True:
        data = conn.recv(1024)
        if not data:
            break
        conn.send('Echo=>%s at %s'%(data, now()))
    conn.close()


def dispatcher():
    while 1:
        conn, add = sockobj.accept()
        print 'ser connected by', add, 'at', now()
        thread.start_new(handleClient, (conn,))

dispatcher()
